package com.zyl.blog.common.domain.rbac.bean;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.zyl.blog.common.service.ITreeNode;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @version v1.0
 * @ProjectName: Personal_Blog_Server
 * @Package: com.zyl.blog.common.domain.rbac.bean
 * @ClassName: Role
 * @Description:  博客角色实体
 * @Author FinalFantasy
 * @Date 2025/8/29-16:14
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@TableName("blog_role")
public class Role implements ITreeNode<BigInteger>, Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    // ================ITreeNode<Long>构造树======================

    @TableField(exist = false)
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<ITreeNode<BigInteger>> roleTree = new ArrayList<>();

    @Override
    @JsonIgnore
    public BigInteger getId() {
        return roleId;
    }

    @Override
    public BigInteger getParentId() {
        return parentId;
    }

    /* 树形结构扩展 */
    /** 完整路径（存储所有父节点ID） */
    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private String ancestors;

    @Override
    public List<ITreeNode<BigInteger>> getChildren() {
        return roleTree;
    }

    @Override
    public void setChildren(List<ITreeNode<BigInteger>> children) {
        this.roleTree = children;
    }
    // ================ITreeNode<Long>构造树======================

    /** 角色ID */
    @TableId(value = "role_id", type = IdType.AUTO)
    @JsonProperty("id")
    private BigInteger roleId;

    /** 角色编码 */
    @TableField("role_code")
    @JsonProperty("code")
    private String roleCode;

    /** 角色名称 */
    @TableField("role_name")
    @JsonProperty("name")
    private String roleName;

    /** 角色描述 */
    @TableField("description")
    @JsonProperty("description")
    private String description;

    /** 角色状态 */
    @TableField("status")
    @JsonProperty("status")
    private Integer status;

    /** 创建时间 */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonProperty(value = "createTime", access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime createTime;

    /** 更新时间 */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonProperty(value = "updateTime", access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime updateTime;

    /** 是否是系统字段（是则不可D操作） */
    @TableField("is_system")
    @JsonProperty("isSystem")
    private Integer isSystem;

    /** 逻辑删除：0=正常，1=已删除 */
    @JsonIgnore
    @TableLogic
    @TableField("is_deleted")
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private Integer deleted;

    /** 父角色ID */
    @TableField("parent_id")
    @JsonProperty("parentId")
    private BigInteger parentId;

}
